package com.elink.enginerring.news.service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.elink.enginerring.common.ErrorType;
import com.elink.enginerring.common.Pagination;
import com.elink.enginerring.news.co.NewsCo;
import com.elink.enginerring.news.dao.NewsMapper;
import com.elink.enginerring.news.entity.News;
import com.elink.enginerring.util.IDGenerator;
import com.elink.enginerring.util.JSONUtil;

@Service
public class NewsService  implements INewsService{
	@Autowired
	private NewsMapper newsMapper;

	@Override
	public Map<String, Object> getListOfPage(NewsCo co) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", newsMapper.selectNewsList(co));
		map.put("pagination", new Pagination(co, newsMapper.selectCount(co)));
		return JSONUtil.getJSON(ErrorType.SUCCESS, map);
	}

	@Override
	public String add(News news) {
		 String newId = IDGenerator.gen32UUID();
		 news.setNewsId(newId);
		 news.setUploadTime(new Date());
		 newsMapper.insertSelective(news);
		return newId;
	}

	@Override
	public Map<String, Object> del(String ids) {
		newsMapper.del(ids);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}

}
